package utils
{
	import core.Configuration;
	
	
	/**
	 * 日历 
	 * @author azhang
	 * 
	 */	
	public class ShowDateListUtil
	{
		
		private static const dateArrayEn:Array = ["Sunday",
												"Monday",
												"Tuesday",
												"Wednesday",
												"Thursday",
												"Friday",
												"Saturday"];
		
		private static const monthArrayEn:Array = ["January",
												 "February",
												 "March",
												 "April",
												 "May",
												 "June",
												 "July",
												 "August",
												 "September",
												 "October",
												 "November",
												 "December"];
		private static const dateArrayCn:Array =   ["星期天",
													"星期一",
													"星期二",
													"星期三",
													"星期四",
													"星期五",
													"星期六"];
		
		private static const monthArrayCn:Array =  ["一月",
													"二月",
													"三月",
													"四月",
													"五月",
													"六月",
													"七月",
													"八月",
													"九月",
													"十月",
													"十一月",
													"十二月"];
		
		private static function get dayArray():Array
		{
			if(Configuration.locale == "en")
			{
				return dateArrayEn;
			}
			
			return dateArrayCn;
		}
		
		private static function get monthArray():Array
		{
			if(Configuration.locale == "en")
			{
				return monthArrayEn;
			}
			
			return monthArrayCn;
		}
		
		//创造出数据
		public static function creatDateList(_dateDelayedNum:uint = 14,_totalNum:uint = 14):Array
		{
			var arr:Array = [];
			var time:Date = TimeUtil.currentGameTime;
			for(var i:int = 0;i < _totalNum ;i++)
			{
				var tempDate:Date = utils.DateUtil.addDays(time,i + _dateDelayedNum);
				var str:String = dayArray[tempDate.getDay()] + "," + monthArray[tempDate.getMonth()] + " " + tempDate.getDate().toString();
				arr.push(str);
			}
			
			return arr;
		}
		
		//返回时间戳
		/**
		 * 现在只能判断大于当前一年的 月份小于当前月份 年数就+1 
		 * 
		 * @param dateStr 接受的字符串的格式 星期,月 日
		 * @return 
		 * 
		 */		
		public static function getDateFromString(dateStr:String = ""):Number
		{
			var time:Date = TimeUtil.currentGameTime;
			var getstr:String = dateStr.split(",")[1];
			var dateArr:Array = getstr.split(" ");
			var monthIndex:int = int(monthArray.indexOf(dateArr[0]));
			
			var year:int = time.getFullYear();
			if(monthIndex == -1)
			{
				throw new Error("这里的年份有错误");
			}
			if(monthIndex < time.getMonth())
			{
				year += 1;
			}
			var tempDate:Date = new Date(year,monthIndex,int(dateArr[1]),0,0,0,0);
			return tempDate.getTime();
		}
		
		
	}
}